package com.woyou.ui.activity;

import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;

import org.androidannotations.annotations.EBean;
import org.apache.http.HttpException;

import android.app.Activity;
import android.widget.Toast;

/**
 * 封装UI界面的逻辑基类
 * @author longtao.li
 *
 */
@EBean
public abstract class SuperPresenter {
	public static final int MAX_WAIT_FOR_WIFI = 20;
	public static final String TAG = "AbstractController";

	protected Activity mActivity;
	
	protected boolean mPaused = true;
	
	
	public void onCreate(Activity activity) {
		mActivity = activity;
	}
	
	
	
	public void onError(Exception exception) {
		if (mActivity == null) {
			return;
		}
		try {
			throw exception;
		} catch (SocketTimeoutException e) {
		} catch (ConnectException e) {
		} catch (IOException e) {
		} catch (HttpException e) {
		} catch (Exception e) {
		} finally {
			exception.printStackTrace();
		}
	}

	public void showToast(final String message) {
		mActivity.runOnUiThread(new Runnable() {
			public void run() {
				Toast toast = Toast.makeText(mActivity, message, Toast.LENGTH_LONG);
				toast.show();
			}
		});
	}

	public void runOnUI(Runnable action) {
		if( mActivity!=null ){
			mActivity.runOnUiThread(action);
		}
		
	}
	
	public void onActivityPause() {
		mPaused = true;
	}

	public void onActivityResume(Activity activity) {
		mActivity = activity;
		mPaused = false;
	}
	
	public void onActivityDestory(){
		
	}

}
